package Day009_Map_斗地主_冒泡排序.ZuoYe;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Test1 {
    public static void main(String[] args) {
        //创建集合
        HashMap<Integer, String> map = new HashMap<>();
        map.put(1, "张三");
        map.put(2, "李四");
        map.put(1, "王五");
        System.out.println(map.size()); // 2
        //键找值
        //获取键
        Set<Integer> set = map.keySet();
        for (Integer key : set) {
            String value = map.get(key);
            System.out.println("键:" + key + " " + "值:" + value);
        }
        //键值对
        //获取键值对对象
        Set<Map.Entry<Integer, String>> entrySet = map.entrySet();
        for (Map.Entry<Integer, String> entry : entrySet) {
            Integer key = entry.getKey();
            String value = entry.getValue();
            System.out.println("键:" + key + " " + "值:" + value);
        }
        //获取键为1 的值
        System.out.println(map.get(1)); //王五
        System.out.println(map.get(10)); //null

        boolean b = map.containsKey(10);
        System.out.println(b); //false

        map.remove(1);
        System.out.println("删除后" + map);
    }
}
